
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>params &#8212; Texas A&amp;M Oil spill / Outfall Calculator 2.1.0 documentation</title>
    <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/doctools.js"></script>
    <script src="../_static/language_data.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
   
  <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
  
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  </head><body>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  <h1>Source code for params</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Params Module</span>
<span class="sd">=============</span>

<span class="sd">Calculate the governing scales and determine the appropriate simulation model</span>

<span class="sd">This module calculates the governing non-dimensional parameters defined in </span>
<span class="sd">papers by Socolofsky and Adams (2002, 2005) and Socolofsky et al. (2011) and</span>
<span class="sd">uses this information to recommend the appropriate simulation model.  </span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="c1"># S. Socolofsky, October 2013, Texas A&amp;M University &lt;socolofs@tamu.edu&gt;.</span>

<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="p">(</span><span class="n">absolute_import</span><span class="p">,</span> <span class="n">division</span><span class="p">,</span> <span class="n">print_function</span><span class="p">)</span>

<span class="kn">from</span> <span class="nn">tamoc</span> <span class="kn">import</span> <span class="n">seawater</span>

<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">scipy.optimize</span> <span class="kn">import</span> <span class="n">fsolve</span>

<div class="viewcode-block" id="Scales"><a class="viewcode-back" href="../autodoc/params/params.Scales.html#params.Scales">[docs]</a><span class="k">class</span> <span class="nc">Scales</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Compute the characteristic scales for a ``TAMOC`` simulation</span>
<span class="sd">    </span>
<span class="sd">    Compute the governing non-dimensional parameters defined in Socolofsky</span>
<span class="sd">    and Adams (2002, 2005) to provide guidance on model selection for the </span>
<span class="sd">    ``TAMOC`` modeling suite.</span>
<span class="sd">    </span>
<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    profile : `ambient.Profile` object</span>
<span class="sd">        Ambient CTD data for the model simulation</span>
<span class="sd">    particles : list</span>
<span class="sd">        List of `stratified_plume_model.Particle` objects that define all of </span>
<span class="sd">        the dispersed phases in the simulation</span>
<span class="sd">    </span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    profile : `ambient.Profile` object</span>
<span class="sd">        Ambient CTD data for the model simulation</span>
<span class="sd">    particles : list</span>
<span class="sd">        List of `stratified_plume_model.Particle` objects for the simulation</span>
<span class="sd">    </span>
<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="Scales.__init__"><a class="viewcode-back" href="../autodoc/params/params.Scales.html#params.Scales.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">particles</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">Scales</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="c1"># Check the data type of the inputs and fix if necessary</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">particles</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
            <span class="n">particles</span> <span class="o">=</span> <span class="p">[</span><span class="n">particles</span><span class="p">]</span>
        
        <span class="c1"># Store the ambient profile data and close any open netCDF files</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">profile</span> <span class="o">=</span> <span class="n">profile</span>
        <span class="n">profile</span><span class="o">.</span><span class="n">close_nc</span><span class="p">()</span>
        
        <span class="c1"># Store the dispersed phase particles</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">particles</span> <span class="o">=</span> <span class="n">particles</span></div>
    
<div class="viewcode-block" id="Scales.simulate"><a class="viewcode-back" href="../autodoc/params/params.Scales.simulate.html#params.Scales.simulate">[docs]</a>    <span class="k">def</span> <span class="nf">simulate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">z_0</span><span class="p">,</span> <span class="n">u_inf</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        docstring for simulate</span>
<span class="sd">        </span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Get the empirical model parameters</span>
        <span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">N</span><span class="p">,</span> <span class="n">u_slip</span><span class="p">,</span> <span class="n">u_inf</span><span class="p">)</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_variables</span><span class="p">(</span><span class="n">z_0</span><span class="p">,</span> <span class="n">u_inf</span><span class="p">)</span>
        
        <span class="c1"># Report the results of the calculations to the screen</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">-- TEXAS A&amp;M OIL-SPILL CALCULATOR (TAMOC) --&#39;</span><span class="p">)</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;-- Empirical Plume Model                  --</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">epm_soln</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">epm_soln</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;Model Parameters:</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">epm_soln</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;   z       = </span><span class="si">%f</span><span class="s1"> (m)</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">z_0</span><span class="p">)</span>
        <span class="n">epm_soln</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;   B       = </span><span class="si">%f</span><span class="s1"> (m^4/s^3)</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">B</span><span class="p">)</span>
        <span class="n">epm_soln</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;   N       = </span><span class="si">%f</span><span class="s1"> (s^(-1))</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">N</span><span class="p">)</span>
        <span class="n">epm_soln</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;   u_slip  = </span><span class="si">%f</span><span class="s1"> (m/s)</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">u_slip</span><span class="p">)</span>
        <span class="n">epm_soln</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;   ua      = </span><span class="si">%f</span><span class="s1"> (m/s)</span><span class="se">\n\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">u_inf</span><span class="p">)</span>
        <span class="n">epm_soln</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;Model Solution:</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">epm_soln</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;   h_T     = </span><span class="si">%f</span><span class="s1"> (m)</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">h_T</span><span class="p">(</span><span class="n">z_0</span><span class="p">))</span>
        <span class="n">epm_soln</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;   h_P     = </span><span class="si">%f</span><span class="s1"> (m)</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">h_P</span><span class="p">(</span><span class="n">z_0</span><span class="p">))</span>
        <span class="n">epm_soln</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;   h_S     = </span><span class="si">%f</span><span class="s1"> (m)</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">h_S</span><span class="p">(</span><span class="n">z_0</span><span class="p">,</span> <span class="n">u_inf</span><span class="p">))</span>
        <span class="n">epm_soln</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;   ua_crit = </span><span class="si">%f</span><span class="s1"> (m/s)</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">u_inf_crit</span><span class="p">(</span><span class="n">z_0</span><span class="p">))</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">epm_soln</span><span class="p">))</span></div>
    
<div class="viewcode-block" id="Scales.save_txt"><a class="viewcode-back" href="../autodoc/params/params.Scales.save_txt.html#params.Scales.save_txt">[docs]</a>    <span class="k">def</span> <span class="nf">save_txt</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">z0</span><span class="p">,</span> <span class="n">u_inf</span><span class="p">,</span> <span class="n">base_name</span><span class="p">,</span> <span class="n">profile_path</span><span class="p">,</span> <span class="n">profile_info</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Save the results to a text file</span>
<span class="sd">        </span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Create the header information</span>
        <span class="n">p_list</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;Empirical Plume Model ASCII output File </span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">]</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;Created: &#39;</span> <span class="o">+</span> <span class="n">datetime</span><span class="o">.</span><span class="n">today</span><span class="p">()</span><span class="o">.</span><span class="n">isoformat</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;Simulation based on CTD data in:</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">profile_path</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">profile_info</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;Row Descriptions:</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    0: release depth (m)</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    1: trap height h_T (m)</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    2: peel height h_P (m)</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    3: separation height h_S (m)</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    4: critical crossflow u_inf_crit (m/s)</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">header</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">p_list</span><span class="p">)</span>
        
        <span class="c1"># Assemble and write the solution data</span>
        <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">z0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">h_T</span><span class="p">(</span><span class="n">z0</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">h_P</span><span class="p">(</span><span class="n">z0</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">h_S</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span> <span class="n">u_inf</span><span class="p">),</span> 
               <span class="bp">self</span><span class="o">.</span><span class="n">u_inf_crit</span><span class="p">(</span><span class="n">z0</span><span class="p">)])</span>
        <span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
        <span class="n">np</span><span class="o">.</span><span class="n">savetxt</span><span class="p">(</span><span class="n">base_name</span> <span class="o">+</span> <span class="s1">&#39;.txt&#39;</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">base_name</span> <span class="o">+</span> <span class="s1">&#39;_header.txt&#39;</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">dat_file</span><span class="p">:</span>
            <span class="n">dat_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">header</span><span class="p">)</span></div>
    
<div class="viewcode-block" id="Scales.get_variables"><a class="viewcode-back" href="../autodoc/params/params.Scales.get_variables.html#params.Scales.get_variables">[docs]</a>    <span class="k">def</span> <span class="nf">get_variables</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">z0</span><span class="p">,</span> <span class="n">u_inf</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Compute the governing variables at a given depth</span>
<span class="sd">        </span>
<span class="sd">        Compute the governing variables B (kinematic buoyancy flux), N </span>
<span class="sd">        (buoyancy frequency) and u_slip (dispersed-phase slip velocity) at </span>
<span class="sd">        the given depth and cross-flow velocity.  These are the main </span>
<span class="sd">        ingredients to each of the scales calculations.</span>
<span class="sd">        </span>
<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        z0 : float</span>
<span class="sd">            Depth to evaluate the governing variables (m)</span>
<span class="sd">        u_inf : float</span>
<span class="sd">            Magnitude of the local ambient cross-flow velocity (m/s)</span>
<span class="sd">        </span>
<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        A tuble containing the governing variables:</span>
<span class="sd">            B : float</span>
<span class="sd">                Total kinematic buoyancy flux of all dispersed phases </span>
<span class="sd">                together (m^4/s^3)</span>
<span class="sd">            N : float</span>
<span class="sd">                Local value of the ambient buoyancy frequency (1/s)</span>
<span class="sd">            u_slip : float</span>
<span class="sd">                Slip velocity of the dispersed phase containing the greatest</span>
<span class="sd">                buoyancy flux (m/s)</span>
<span class="sd">            u_inf : float</span>
<span class="sd">                Magnitude of the local ambient cross-flow velocity (m/s)</span>
<span class="sd">                TODO (S. Socolofsky, October 2013): Eventually, this should</span>
<span class="sd">                be read from the ambient CTD data and removed as an input to</span>
<span class="sd">                this method.</span>
<span class="sd">        </span>
<span class="sd">        Notes</span>
<span class="sd">        -----</span>
<span class="sd">        When more than one dispersed phase particle is present, the slip </span>
<span class="sd">        velocity used as the governing variables is the value for the </span>
<span class="sd">        dispersed phase particle that has the greatest effect on the dynamics</span>
<span class="sd">        of the plume.  This particle is the one for which the buoyancy flux</span>
<span class="sd">        is highest.  The governing variables, B, on the other hand is the </span>
<span class="sd">        total buoyancy flux of all dispersed phase particles combined.  This </span>
<span class="sd">        is consistent with the way the governing parameters have been used </span>
<span class="sd">        in papers by Socolofsky and Adams (e.g., Socolofsky et al. 2011).</span>
<span class="sd">        </span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Get the ambient data from the CTD profile</span>
        <span class="n">Ta</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">P</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">profile</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;temperature&#39;</span><span class="p">,</span> <span class="s1">&#39;salinity&#39;</span><span class="p">,</span>
                                            <span class="s1">&#39;pressure&#39;</span><span class="p">])</span>
        <span class="n">rho</span> <span class="o">=</span> <span class="n">seawater</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">Ta</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">P</span><span class="p">)</span>
        
        <span class="c1"># Compute the properties of each dispersed-phase particle</span>
        <span class="n">us</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">))</span>
        <span class="n">rho_p</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">))</span>
        <span class="n">m_p</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">))</span>
        <span class="n">B_p</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">))</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">)):</span>
            <span class="n">m0</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">m0</span>
            <span class="n">T0</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">T0</span>
            <span class="n">m_p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">m0</span><span class="p">)</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">nb0</span>
            <span class="k">if</span> <span class="n">m_p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mf">0.</span><span class="p">:</span>
                <span class="c1"># Particles exist, get properties.  Make sure the algorithm </span>
                <span class="c1"># uses the dirty bubble properties since this is supposed</span>
                <span class="c1"># to be the rise velocity averaged over the whole plume.</span>
                <span class="n">us</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">rho_p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">properties</span><span class="p">(</span><span class="n">m0</span><span class="p">,</span> <span class="n">T0</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> 
                                 <span class="n">Ta</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">inf</span><span class="p">)[</span><span class="mi">0</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span>
                <span class="n">B_p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">rho</span> <span class="o">-</span> <span class="n">rho_p</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">/</span> <span class="n">rho</span> <span class="o">*</span> <span class="mf">9.81</span> <span class="o">*</span> <span class="p">(</span><span class="n">m_p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">/</span> <span class="n">rho_p</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c1"># Particles dissolved, set to ambient conditions</span>
                <span class="n">us</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.</span>
                <span class="n">rho_p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">rho</span>
                <span class="n">B_p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.</span>
        
        <span class="c1"># Select the correct slip velocity</span>
        <span class="n">u_slip</span> <span class="o">=</span> <span class="n">us</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">B_p</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">B_p</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
                <span class="n">u_slip</span> <span class="o">=</span> <span class="n">us</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span>
        
        <span class="c1"># Compute the total buoyancy flux</span>
        <span class="n">B</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">B_p</span><span class="p">)</span>
        
        <span class="c1"># Get the ambient buoyancy frequency</span>
        <span class="n">N</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">profile</span><span class="o">.</span><span class="n">buoyancy_frequency</span><span class="p">(</span><span class="n">z0</span><span class="p">)</span>
        
        <span class="c1"># Return the governing parameters</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">N</span><span class="p">,</span> <span class="n">u_slip</span><span class="p">,</span> <span class="n">u_inf</span><span class="p">)</span></div>
    
<div class="viewcode-block" id="Scales.h_T"><a class="viewcode-back" href="../autodoc/params/params.Scales.h_T.html#params.Scales.h_T">[docs]</a>    <span class="k">def</span> <span class="nf">h_T</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">z0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Compute the trap height for the lowest intrusion</span>
<span class="sd">        </span>
<span class="sd">        Compute the intrusion layer height above the bottom for the lowest</span>
<span class="sd">        intrusion based on the correlations in Socolofsky and Adams (2005).</span>
<span class="sd">        </span>
<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        z0 : float</span>
<span class="sd">            Depth to evaluate the trap height (m)</span>
<span class="sd">        </span>
<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        h_T : float</span>
<span class="sd">            Plume trap height for the first intrusion measured in height </span>
<span class="sd">            above the bottom (m)</span>
<span class="sd">        </span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Get the governing variables</span>
        <span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">N</span><span class="p">,</span> <span class="n">u_slip</span><span class="p">,</span> <span class="n">u_inf</span><span class="p">)</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_variables</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span> <span class="mf">0.</span><span class="p">)</span>
        
        <span class="c1"># Compute U_N</span>
        <span class="n">U_N</span> <span class="o">=</span> <span class="n">u_slip</span> <span class="o">/</span> <span class="p">(</span><span class="n">B</span> <span class="o">*</span> <span class="n">N</span><span class="p">)</span><span class="o">**</span><span class="p">(</span><span class="mf">1.</span><span class="o">/</span><span class="mf">4.</span><span class="p">)</span>
        
        <span class="c1"># Compute the correlation equation</span>
        <span class="k">return</span> <span class="mf">2.9</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="p">(</span><span class="n">U_N</span> <span class="o">-</span> <span class="mf">1.0</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">/</span> <span class="mf">28.09</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">B</span> <span class="o">/</span> <span class="n">N</span><span class="o">**</span><span class="mi">3</span><span class="p">)</span><span class="o">**</span><span class="p">(</span><span class="mf">1.</span><span class="o">/</span><span class="mf">4.</span><span class="p">)</span></div>
    
<div class="viewcode-block" id="Scales.h_P"><a class="viewcode-back" href="../autodoc/params/params.Scales.h_P.html#params.Scales.h_P">[docs]</a>    <span class="k">def</span> <span class="nf">h_P</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">z0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Compute the peel height for the lowest intrusion</span>
<span class="sd">        </span>
<span class="sd">        Compute the height above the bottom for the peeling region that forms</span>
<span class="sd">        the lowest intrusion based on the correlations in Socolofsky and Adams </span>
<span class="sd">        (2005).</span>
<span class="sd">        </span>
<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        z0 : float</span>
<span class="sd">            Depth to evaluate the trap height (m)</span>
<span class="sd">        </span>
<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        h_P : float</span>
<span class="sd">            Plume peel height for the first intrusion measured in height </span>
<span class="sd">            above the bottom (m)</span>
<span class="sd">        </span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Get the governing variables</span>
        <span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">N</span><span class="p">,</span> <span class="n">u_slip</span><span class="p">,</span> <span class="n">u_inf</span><span class="p">)</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_variables</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span> <span class="mf">0.</span><span class="p">)</span>
        
        <span class="c1"># Compute U_N</span>
        <span class="n">U_N</span> <span class="o">=</span> <span class="n">u_slip</span> <span class="o">/</span> <span class="p">(</span><span class="n">B</span> <span class="o">*</span> <span class="n">N</span><span class="p">)</span><span class="o">**</span><span class="p">(</span><span class="mf">1.</span><span class="o">/</span><span class="mf">4.</span><span class="p">)</span>
        
        <span class="c1"># Compute the correlation equation</span>
        <span class="k">return</span> <span class="mf">5.2</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="p">(</span><span class="n">U_N</span> <span class="o">-</span> <span class="mf">1.8</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">/</span> <span class="mf">10.24</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">B</span> <span class="o">/</span> <span class="n">N</span><span class="o">**</span><span class="mi">3</span><span class="p">)</span><span class="o">**</span><span class="p">(</span><span class="mf">1.</span><span class="o">/</span><span class="mf">4.</span><span class="p">)</span></div>
    
<div class="viewcode-block" id="Scales.h_S"><a class="viewcode-back" href="../autodoc/params/params.Scales.h_S.html#params.Scales.h_S">[docs]</a>    <span class="k">def</span> <span class="nf">h_S</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">z0</span><span class="p">,</span> <span class="n">u_inf</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Compute the cross-flow separation height</span>
<span class="sd">        </span>
<span class="sd">        Compute the height above the bottom where the cross-flow causes </span>
<span class="sd">        separation of the entrained plume fluid from the plume based on the</span>
<span class="sd">        correlation in Socolofsky and Adams (2002).</span>
<span class="sd">        </span>
<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        z0 : float</span>
<span class="sd">            Depth to evaluate the trap height (m)</span>
<span class="sd">        u_inf : float</span>
<span class="sd">            Magnitude of the local ambient cross-flow velocity (m/s)</span>
<span class="sd">        </span>
<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        h_S : float</span>
<span class="sd">            Cross-flow separation height measured in height above the bottom </span>
<span class="sd">            (m)</span>
<span class="sd">        </span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Get the governing variables</span>
        <span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">N</span><span class="p">,</span> <span class="n">u_slip</span><span class="p">,</span> <span class="n">u_inf</span><span class="p">)</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_variables</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span> <span class="n">u_inf</span><span class="p">)</span>
        
        <span class="c1"># Compute the correlation equation</span>
        <span class="k">return</span> <span class="mf">5.1</span> <span class="o">*</span> <span class="n">B</span> <span class="o">/</span> <span class="p">(</span><span class="n">u_inf</span> <span class="o">*</span> <span class="n">u_slip</span><span class="o">**</span><span class="mf">2.4</span><span class="p">)</span><span class="o">**</span><span class="p">(</span><span class="mf">0.88</span><span class="p">)</span></div>
    
<div class="viewcode-block" id="Scales.lambda_1"><a class="viewcode-back" href="../autodoc/params/params.Scales.lambda_1.html#params.Scales.lambda_1">[docs]</a>    <span class="k">def</span> <span class="nf">lambda_1</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">z0</span><span class="p">,</span> <span class="n">n</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Compute the spreading ratio of particle n at the given depth</span>
<span class="sd">        </span>
<span class="sd">        Compute the spreading ratio lambda_1 for particle n at the given </span>
<span class="sd">        depth z0 from the correlation equations in Socolofsky and Adams </span>
<span class="sd">        (2005).</span>
<span class="sd">        </span>
<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        z0 : float</span>
<span class="sd">            Depth to evaluate the trap height (m)</span>
<span class="sd">        n : int</span>
<span class="sd">            Index to the self.Particle object for which the spreading ratio</span>
<span class="sd">            should be calculated</span>
<span class="sd">        </span>
<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        lambda_1 : float</span>
<span class="sd">            Dispersed-phase spreading ratio lambda_1 for the selected </span>
<span class="sd">            dispersed-phase particle.</span>
<span class="sd">        </span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Get the governing variables</span>
        <span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">N</span><span class="p">,</span> <span class="n">u_slip</span><span class="p">,</span> <span class="n">u_inf</span><span class="p">)</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_variables</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span> <span class="mf">0.</span><span class="p">)</span>
        
        <span class="c1"># Compute the slip velocity for the selected dispersed-phase particle.</span>
        <span class="c1"># Make sure the algorithm uses the dirty bubble properties since this</span>
        <span class="c1"># is supposed to be the rise velocity averaged over the whole plume.</span>
        <span class="n">Ta</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">P</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">profile</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;temperature&#39;</span><span class="p">,</span> <span class="s1">&#39;salinity&#39;</span><span class="p">,</span>
                                            <span class="s1">&#39;pressure&#39;</span><span class="p">])</span>
        <span class="n">u_slip</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">n</span><span class="p">]</span><span class="o">.</span><span class="n">properties</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">n</span><span class="p">]</span><span class="o">.</span><span class="n">m0</span><span class="p">,</span> 
                                              <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">n</span><span class="p">]</span><span class="o">.</span><span class="n">T0</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> 
                                              <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">inf</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
        
        <span class="c1"># Compute the particle value of U_N</span>
        <span class="n">U_N</span> <span class="o">=</span> <span class="n">u_slip</span> <span class="o">/</span> <span class="p">(</span><span class="n">B</span> <span class="o">*</span> <span class="n">N</span><span class="p">)</span><span class="o">**</span><span class="p">(</span><span class="mf">1.</span><span class="o">/</span><span class="mf">4.</span><span class="p">)</span>
        
        <span class="c1"># Get the spreading ratio</span>
        <span class="k">return</span> <span class="mf">1.0</span> <span class="o">-</span> <span class="mf">0.19</span> <span class="o">*</span> <span class="n">U_N</span><span class="o">**</span><span class="p">(</span><span class="mf">0.61</span><span class="p">)</span></div>
    
<div class="viewcode-block" id="Scales.u_inf_crit"><a class="viewcode-back" href="../autodoc/params/params.Scales.u_inf_crit.html#params.Scales.u_inf_crit">[docs]</a>    <span class="k">def</span> <span class="nf">u_inf_crit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">z0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Determine the critical cross-flow velocity</span>
<span class="sd">        </span>
<span class="sd">        Calculate the critical value of the cross-flow velocity for which </span>
<span class="sd">        the peel height matches the cross-flow separation height.</span>
<span class="sd">        </span>
<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        z0 : float</span>
<span class="sd">            Depth to evaluate the trap height (m)</span>
<span class="sd">        </span>
<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        u_inf_crit : float</span>
<span class="sd">            Crossflow velocity for which h_P = h_S</span>
<span class="sd">        </span>
<span class="sd">        </span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Get h_P, which is independent of the crossflow velocity</span>
        <span class="n">h_P</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">h_P</span><span class="p">(</span><span class="n">z0</span><span class="p">)</span>
        
        <span class="c1"># Define an objective function for root finding</span>
        <span class="k">def</span> <span class="nf">residual</span><span class="p">(</span><span class="n">us</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Residual for use in root finding to find u_inf_crit</span>
<span class="sd">            </span>
<span class="sd">            Returns the difference h_S - h_P, which should be zero at the </span>
<span class="sd">            critical cross-flow velocity.</span>
<span class="sd">            </span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">h_S</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span> <span class="n">us</span><span class="p">)</span> <span class="o">-</span> <span class="n">h_P</span>
        
        <span class="c1"># Return the critical crossflow velocity</span>
        <span class="k">return</span> <span class="n">fsolve</span><span class="p">(</span><span class="n">residual</span><span class="p">,</span> <span class="mf">0.0001</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span></div></div>

</pre></div>

          </div>
          
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="../index.html">Texas A&M Oil spill / Outfall Calculator</a></h1>








<h3>Navigation</h3>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../user_manual.html">TAMOC User Manual</a></li>
<li class="toctree-l1"><a class="reference internal" href="../unit_tests.html">Unit Tests</a></li>
<li class="toctree-l1"><a class="reference internal" href="../glossary.html">Glossary</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../bugs.html">Reporting Bugs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../readme.html">Read Me File</a></li>
<li class="toctree-l1"><a class="reference internal" href="../release.html">Release Notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="../license.html">License</a></li>
</ul>

<div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="../index.html">Documentation overview</a><ul>
  <li><a href="index.html">Module code</a><ul>
  </ul></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>








        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy;2020, Scott A. Socolofsky.
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 2.4.4</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
      
    </div>

    

    
  </body>
</html>